from my_base_sk.MySK import *

prompt = """对话历史如下:
{{$history}}
---
User: {{$request}}
Assistant:  """

# 定义 Prompt 模板
# 模板中，变量以 {{$变量名}} 表示
prompt_template_config = PromptTemplateConfig(
    template=prompt,
    description="Multi-turn dialogue",
    execution_settings={service_id: req_settings},
    input_variables=[
        InputVariable(name="request", description="The user input", is_required=True),
        InputVariable(name="history", description="The dialogue history", is_required=True),
    ],
)

# 注册 function
chat = kernel.add_function(
    function_name="chat",
    plugin_name="MyDemoPlugin",
    prompt_template_config=prompt_template_config,
)

from semantic_kernel.contents import ChatHistory

chat_history = ChatHistory()
chat_history.add_system_message("You are a helpful chatbot who is good at answering user's questions.")

while True:
    request = input("User > ").strip()
    if not request:
        break
    result = asyncio.run(
        run_function(chat, KernelArguments(request=request, history=chat_history)),
    )

    print(f"Assistant > {result}")
    chat_history.add_user_message(request)
    chat_history.add_assistant_message(str(result))

